package com.wxq.demo.controller;

import com.wxq.demo.pojo.Book;
import com.wxq.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {
    @Autowired
    private BookService bookService;

    @GetMapping("/test")
    public void test() {
        //模拟一次数据请求后存在缓存中
        bookService.getBookById(1);
        //第二次直接缓存中获取
        bookService.getBookById(1);
        //清除缓存
        bookService.deleteBookById(1);
        Book book = bookService.getBookById(1);
        System.out.println("book:" + book.getId() + ";" + book.getName() + ";" + book.getAuthor());
        //修改缓存内容
        Book book1 = new Book();
        book1.setName("三国演义");
        book1.setAuthor("罗贯中");
        book1.setId(1);
        bookService.updateBookById(book1);
        Book book2 = bookService.getBookById(1);
        System.out.println("book2:" + book2.getId() + ";" + book2.getName() + ";" + book2.getAuthor());

    }
}
